import redis


class RedisCon:
    def __init__(self):
        self.conn = redis.Redis(host='localhost', port=6379)

    # 字符串存
    def set_str(self, key, value, time=''):
        if time:
            self.conn.setex(key, time, value)
        else:
            self.conn.set(key, value)

    # 字符串取
    def get_str(self, key):
        value = self.conn.get(key)
        if value:
            value = str(value, encoding='utf8')
        return value

    # 删除字符串
    def del_str(self, key):
        self.conn.delete(key)


r = RedisCon()
# r.set_str('name1', 'aaaa')
# print(r.get_str('name1'))

